#include "taiic_lr.h"
#include "taiic_lr_config.h"

 void load_ir_configs(sample_smartIr_t* ctx)
{
    sample_smartIr_t* smartIr_ctx = ctx;
    rk_smart_ir_result_t ir_init_res;

    smartIr_ctx->ir_cut_v4ldev = NULL;
    smartIr_ctx->ir_v4ldev = NULL;

    smartIr_ctx->ir_cut_v4ldev = DEVICE_NAME;
    smartIr_ctx->ir_configs.d2n_envL_th = D2N_TH;
    smartIr_ctx->ir_configs.n2d_envL_th = N2D_TH;
    smartIr_ctx->ir_configs.rggain_base = RGGAIN_BASE;
    smartIr_ctx->ir_configs.bggain_base = BGGAIN_BASE;
    smartIr_ctx->ir_configs.awbgain_rad = AWBGAIN_RAD;
    smartIr_ctx->ir_configs.awbgain_dis = AWBGAIN_DIS;
    smartIr_ctx->ir_configs.switch_cnts_th = SWITCH_CNTS_TH;
    rk_smart_ir_config(smartIr_ctx->ir_ctx, &smartIr_ctx->ir_configs);
    // set initial status to day
    ir_init_res.status = RK_SMART_IR_STATUS_DAY;
    rk_smart_ir_set_status(smartIr_ctx->ir_ctx, ir_init_res);
}

int get_ir_result(sample_smartIr_t* ctx)
{
    rk_aiq_isp_stats_t *stats_ref = NULL;
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    ret = rk_aiq_uapi2_sysctl_get3AStatsBlk(ctx->aiq_ctx, &stats_ref, -1);
    if (ret == XCAM_RETURN_NO_ERROR && stats_ref != NULL)
    {
        rk_smart_ir_runOnce(ctx->ir_ctx, stats_ref, &ctx->ir_res);
        rk_aiq_uapi2_sysctl_release3AStatsRef(ctx->aiq_ctx, stats_ref);
        
        return  ctx->ir_res.status;
    }
    else
    {
        return -1;
    }
}

int  init_ir_ctx(sample_smartIr_t* ctx)
{
    ctx->ir_ctx = NULL;
    if(ctx->aiq_ctx == NULL)
    {
        ERR("%s, ctx is nullptr\n", __FUNCTION__);
        return XCAM_RETURN_ERROR_PARAM;
    }
}